home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / bootslow.zip / SOURCE.ZIP / SLOW.ASM < prev    next >
Assembly Source File  |  1991-08-06  |  7KB  |  373 lines

  1. ;
  2. ;; SlowDown for self-booting software
  3. ;;
  4. ;; BOOTSLOW
  5. ;;
  6. ;; Copyright 1991 Alexander R. Pruss
  7. ;;
  8. ;; May be freely distributed, modified and used provided that no copyright
  9. ;; messages are removed, and this sentence together with the next two are
  10. ;; always included in unmodified form.  If you like this program a lot, you are
  11. ;; invited to show your appreciation by making a tax-deductible donation to
  12. ;; the Pro-Life or Anti-Abortion movement, but are under no obligation, moral
  13. ;; or otherwise to do so (especially if you disagree with the goals of this
  14. ;; movement.)  There is no warranty; use at own risk.
  15. ;
  16. DefaultSlowdown = 200
  17. StackSize = 1024
  18.  
  19.     include macros.inc
  20.  
  21. BiSeg segment at 0040h
  22.     org 13h
  23.     bios_memory dw ?
  24. BiSeg ends
  25.  
  26. SillySeg segment at 0ABCDh
  27.     org 80h
  28.     CmdHead db ?
  29. SillySeg ends
  30.  
  31. ZeroSeg segment at 0
  32.     org 8h*4
  33. Inter8 label dword
  34. Inter8l dw ?
  35. Inter8h dw ?
  36.     org 13h*4
  37. Inter13 label dword
  38. Inter13l dw ?
  39. Inter13h dw ?
  40. ZeroSeg ends
  41.  
  42. c segment
  43.     org 100h
  44.     assume cs:c,ss:NOTHING
  45.  
  46. StartResident:
  47.  
  48. ResidentSize = offset EndResident - offset StartResident
  49. ResInK = (ResidentSize+1023)/1024
  50.  
  51. TOP:
  52.     jmp Install
  53.  
  54. disk_level dw 0
  55. factor dw DefaultSlowdown
  56.  
  57. old8 label dword
  58. o8l dw ?
  59. o8h dw ?
  60.  
  61. old13 label dword
  62. o13l dw ?
  63. o13h dw ?
  64.  
  65.     assume ds:NOTHING, es:NOTHING, cs:c
  66. i8h:
  67.     cmp cs:disk_level,0
  68.     jz SlowDown
  69. GoThru8:
  70.     jmp dword ptr cs:old8
  71.  
  72. SlowDown:
  73.     push cx
  74.     push ax
  75.     mov al,3
  76.     mov cx,cs:factor
  77. LoopTop:
  78.     mul al
  79.     add ax,cs:o8h
  80.     sub ax,cs:o8l
  81.     mul al
  82.     mul al
  83.     mul al
  84.     loop LoopTop
  85.     pop ax
  86.     pop cx
  87.     jmp GoThru8
  88.  
  89. i13h:
  90.     pushf
  91.     inc cs:disk_level
  92.     call dword ptr cs:old13
  93.     pushf
  94.     dec cs:disk_level
  95.     popf
  96.     retf 2
  97.  
  98. EndResident:
  99.  
  100.          assume ds:c, es:NOTHING, cs:c
  101. getAXd proc near
  102.     L1:  xor ax,ax
  103.          xor bx,bx
  104.          cmp si,cx
  105.          jae R1
  106.          mov bl,[si]
  107.          inc si
  108.          cmp bl,'0'
  109.          jb L1
  110.          cmp bl,'9'
  111.          ja L1
  112.          sub bl,'0'
  113.          mov al,bl
  114.     L2:  cmp si,cx
  115.          jae R1
  116.          mov bl,[si]
  117.          inc si
  118.          cmp bl,'0'
  119.          jb R1
  120.          cmp bl,'9'
  121.          ja R1
  122.          sub bl,'0'
  123.          mov dx,10
  124.          mul dx
  125.          add ax,bx
  126.          jmp L2
  127.     R1:  ret
  128. getAXd endp
  129.  
  130.          assume ds:c, es:NOTHING, cs:c
  131. _puts proc near
  132. top:
  133.     mov bx,1
  134.     mov dx,si
  135.     mov ah,WriteHandle
  136.     int 21h
  137.     ret
  138. _puts endp
  139.  
  140. DiskCheckNo:
  141.     mov disk_check,0
  142.     jmp parsetop
  143.  
  144. OutOfMemory:
  145.     Puts NoMem
  146.     mov ax,4c10h
  147.     int 21h
  148.  
  149. ;;
  150. ;; Installation
  151. ;;
  152.  
  153. Install:
  154.     assume ds:c
  155.     cld
  156.  
  157.     Puts copyright
  158.  
  159.     cmp sp,offset stack_bottom+StackSize
  160.     jbe OutOfMemory
  161.  
  162.     mov sp,offset stack_bottom+StackSize
  163.     assume es:ZeroSeg
  164.     Clear ax
  165.     mov es,ax
  166.     mov ax,es:bios_memory
  167.     sub ax,ResInK         ; subtract size of resident module in Kb
  168.     mov NewMem,ax         ; save new total memory size
  169.     mov bx,1024/16
  170.     mul bx                ; ax is total memory in paragraphs
  171.     mov bx,cs
  172.     add bx,(stack_bottom-TOP+100h+StackSize+2+15)/16   ; paragraph of end of prog
  173.     cmp ax,bx
  174.     jb OutOfMemory
  175.     sub ax,10h            ; resident starts now at ax:0100h
  176.     mov NewSeg,ax         ; save resident segment
  177.  
  178.     assume ds:SillySeg, es:NOTHING
  179.     Clear ch
  180.     mov cl,CmdHead
  181.     assume ds:c
  182.     mov si,81h
  183.     add cx,si
  184. parsetop:
  185.     cmp si,cx
  186.     jae PARSER_DONE
  187.     lodsb
  188.     cmp al,'d'
  189.     jz DiskCheckNo
  190.     cmp al,'D'
  191.     jz DiskCheckNo
  192.     cmp al,'0'
  193.     jb parsetop
  194.     cmp al,'9'
  195.     ja parsetop
  196.     dec si
  197.     call getAXd
  198.     mov factor,AX
  199. PARSER_DONE:
  200.  
  201. ;; Load interrupt table now ;;
  202.  
  203.     mov ax,OpenRDOnly
  204.     mov dx,offset filename
  205.     int 21h
  206.     jc _openerror
  207.     mov bx,ax
  208.     mov ah,ReadHandle
  209.     mov cx,4*256
  210.     mov dx,offset itable
  211.     int 21h
  212.     pushf
  213.     mov ah,CloseHandle
  214.     int 21h
  215.     popf
  216.     jnc Nopenerror
  217.  
  218. _openerror: jmp openerror
  219. _Abort: jmp abort
  220.  
  221. Nopenerror:
  222.  
  223. ;; Load boot sector ;;
  224.  
  225.     Puts drive_q
  226. g1:
  227.     DOSGetch
  228.     cmp al,01bh
  229.     jz _Abort
  230.     or al,TOLOWER
  231.     cmp al,'a'
  232.     jb g1
  233.     cmp al,'z'
  234.     ja g1
  235.     sub al,'a'
  236.     mov bx,offset bootsec
  237.     mov cx,1
  238.     Clear dx
  239.     int 25h
  240.     jnc NLowLevelError
  241.  
  242. jmp LowLevelError
  243.  
  244. NLowLevelError:
  245.     Puts booting
  246.  
  247. ;;
  248. ;; We're unstoppable now!
  249. ;;
  250.  
  251.     Clear ax
  252.     mov es,ax
  253.     assume es:ZeroSeg
  254.  
  255. ;; Copy interrupt table
  256.  
  257.     mov si,offset itable
  258.     Clear di
  259.     mov cx,256*4/2
  260.     cli
  261. rep movsw
  262.     sti
  263.  
  264. ;;
  265. ;; Copy boot sector (es=0000)
  266. ;;
  267.     mov si,offset bootsec
  268.     mov di,BootPos
  269.     mov cx,512/2
  270. rep movsw
  271.  
  272. ;;
  273. ;; (es=0000)
  274. ;; Save original interrupts
  275. ;;
  276.     push es
  277.     pop ds
  278.     assume ds:ZeroSeg, es:NOTHING
  279.  
  280.     les ax,dword ptr Inter8
  281.     mov cs:o8l,ax
  282.     mov cs:o8h,es
  283.     les ax,dword ptr Inter13
  284.     mov cs:o13l,ax
  285.     mov cs:o13h,es
  286.  
  287.     push cs
  288.     pop ds
  289.     assume ds:c
  290.  
  291. ;;
  292. ;; Copy to high memory, adjusting maximum memory available
  293. ;;
  294.  
  295.     Clear ax
  296.     mov es,ax
  297.  
  298.     assume es:ZeroSeg
  299.     mov ax,NewMem
  300.     mov es:bios_memory,ax
  301.  
  302.     assume es:NOTHING
  303.     mov es,NewSeg
  304.     mov cx,(EndResident-StartResident+1)/2
  305.     mov si,offset StartResident
  306.     mov di,si
  307. rep movsw      ; Copy to high memory
  308.  
  309. ;; O.K.  The memory is all set up.  Just need to put in the interrupt
  310. ;; tables
  311.  
  312. ;; es points to the new segment
  313.  
  314.     Clear ax
  315.     mov ds,ax
  316.     assume ds:ZeroSeg
  317.     cli
  318.     mov Inter8l,offset i8h
  319.     mov Inter8h,es
  320.     cmp cs:disk_check,0
  321.     jz ND
  322.     mov Inter13l,offset i13h
  323.     mov Inter13h,es
  324. ND:
  325.     sti
  326.  
  327. ;; Well, well, well.  All done, almost.  Just set the registers and jump.
  328.     Clear ax
  329.     cli
  330.     mov ss,ax
  331.     mov sp,BootPos-2
  332.     sti
  333.     db 0EAh  ; Far jump
  334.     dw BootPos
  335.     dw 0000
  336. ;; We're in! ;;
  337.  
  338.  
  339. LowLevelError:
  340.     Puts ll_error
  341.     mov ax,4c01h
  342.     int 21h
  343.  
  344. openerror:
  345.     Puts cantopen
  346.     mov ax,4c02h
  347.     int 21h
  348.  
  349. abort:
  350.     Puts aborted
  351.     mov ax,4c00h
  352.     int 21h
  353.  
  354. String   copyright, <'Self-Booting Disk Slowdown.', CR,LF, '(C) Copyright 1991 Alexander Pruss.', CR,LF>
  355. String   NoMem, <'Not enough memory.', CR,LF>
  356. String   cantopen, <'Error reading boot.itb.',CR,LF>
  357. String   drive_q, <'Choose DOS drive to boot: (A,B,C,etc.), ESC to abort.', CR,LF>
  358. String   aborted, <'Aborted.',CR,LF>
  359. String   ll_error, <'Error reading boot sector.',CR,LF>
  360. String   booting, <'Booting...',CR,LF>
  361. filename db 'boot.itb',00
  362. disk_check db 1
  363. NewSeg   dw ?
  364. NewMem   dw ?
  365. bootsec label byte
  366. itable = bootsec+512
  367.  
  368. stack_bottom = itable+1024+512   ; extra 512 for safety
  369.  
  370. c ends
  371.  
  372. end TOP
  373.